﻿/*
Copyright © 2010 François Karman

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

See <license.txt> for the complete license of the software.
*/

using System.IO;

namespace MSBuild.Mercurial
{
    /// <summary>
    /// Initializes a new Mercurial repository.
    /// </summary>
    [Command("init")]
    public class HgInit : AbstractHgTask
    {
        /// <summary>
        /// Gets or sets the ssh command to use.
        /// </summary>
        [Parameter("-e")]
        public string Ssh { get; set; }

        /// <summary>
        /// Gets or sets the path of the new repository.
        /// </summary>
        /// <remarks>
        /// This property is an alias for the
        /// <c>HgInit.LocalPath</c> property.
        /// </remarks>
        [Parameter("")]
        public string Destination
        {
            get { return this.LocalPath; }
            set { this.LocalPath = value; }
        }

        /// <summary>
        /// Executes the associated Mercurial command and
        /// creates the destination directory if necessary.
        /// </summary>
        /// <returns>
        /// <c>true</c> if the task successfully executed; otherwise, <c>false</c>.
        /// </returns>
        public override bool Execute()
        {
            if (!Directory.Exists(this.Destination))
            {
                Directory.CreateDirectory(this.Destination);
            }

            return base.Execute();
        }
    }
}
